package com.wanxi.education.controller.front;

import com.github.pagehelper.PageInfo;
import com.wanxi.education.common.CommonResult;
import com.wanxi.education.model.vo.catalogue.CatalogueVo;
import com.wanxi.education.model.vo.course.*;
import com.wanxi.education.model.vo.history.HistoryAcceptVo;
import com.wanxi.education.model.vo.history.HistoryVo;
import com.wanxi.education.service.CourseFrontService;
import com.wanxi.education.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: yanguangqiong
 * @Description:
 * @Date: Created in 2021/9/24
 * @Version: 1.0
 */
@Api(tags = "前端课程管理")
@RestController
@RequestMapping("/user/front/course")
public class CourseFrontController {

    @Autowired
    private CourseFrontService courseFrontService;

    //TODO session 暂时用的固定数据
    @PostMapping("/addHistory")
    @ApiOperation("添加当前课程观看记录")
    public CommonResult addHistory(@RequestBody AddHistoryVo addHistoryVo,HttpSession httpSession){
        Long loginCid = (Long) httpSession.getAttribute("loginCId");
        courseFrontService.addHistory(addHistoryVo,loginCid);
        return CommonResult.success("成功");
    }

    @PostMapping("/findPageForHome")
    @ApiOperation("首页课程列表")
    public CommonResult<PageInfo<CourseHomeVo>> findPageForHome(@RequestBody CourseFindPageVo courseFindPageVo) {
        PageInfo<CourseHomeVo> pageInfo = courseFrontService.findPageForHome(courseFindPageVo);
        return CommonResult.success(pageInfo);
}



    @PostMapping("/findCarouselForHome")
    @ApiOperation("首页轮播课程列表")
    public CommonResult<List<CourseHomeVo>> findCarouselForHome() {
        List<CourseHomeVo> list = courseFrontService.findCarouselForHome();
        return CommonResult.success(list);
    }
//    通过首页点击课程进入课程详情
    @GetMapping("/findByIdToHome")
    @ApiOperation("课程详情")
    public CommonResult<CourseByIdVo> findByIdToHome(@RequestParam("courseId") Long courseId) {
        CourseByIdVo courseByIdVO = courseFrontService.findByIdToHome(courseId);
        return CommonResult.success(courseByIdVO);
    }
//    通过首页点击课程进入课程详情对应的目录
    @GetMapping("/findCatalogueByCourseId")
    @ApiOperation("课程目录")
    public CommonResult<List<CatalogueVo>> findCatalogueByCourseId(@RequestParam("courseId") Long courseId) {
        List<CatalogueVo> catalogueByCourseId = courseFrontService.findCatalogueByCourseId(courseId);
        return CommonResult.success(catalogueByCourseId);
    }
//    通过个人中心点击我的课程进入个人课程列表
    @PostMapping("/findPageForPersonage")
    @ApiOperation("个人中心课程列表，需要登录")
    public CommonResult<PageInfo<CourseHomeVo>> findPageForPersonage(@RequestBody CourseFindPageForPersonageVo courseFindPageForPersonageVo,HttpSession session) {
        Long userId = (Long) session.getAttribute("loginCId");
        courseFindPageForPersonageVo.setUserId(userId);
        PageInfo<CourseHomeVo> pageInfo =  courseFrontService.findPageForPersonage(courseFindPageForPersonageVo);
        return CommonResult.success(pageInfo);
    }
//    通过个人中心我的课程进入课程详情
    @GetMapping("/findByIdForPersonage")
    @ApiOperation("个人中心课程详情，需要登录")
    public CommonResult<CourseByIdVo> findByIdForPersonage(@RequestParam("courseId") Long courseId) {
        CourseByIdVo courseByIdVO = courseFrontService.findByIdToHome(courseId);
        return CommonResult.success(courseByIdVO);
    }
//    个人中心课程目录
    @GetMapping("/findCatalogueByCourseIdForPersonage")
    @ApiOperation("个人中心课程目录")
    public CommonResult<List<CatalogueVo>> findCatalogueByCourseIdForPersonage(@RequestParam("courseId") Long courseId) {
//        C端用户登录的id，用于查询课程目录
        List<CatalogueVo> list = courseFrontService.findCatalogueByCourseIdForPersonage(courseId);
        return CommonResult.success(list);
    }
//    历史记录

    //TODO session 暂时用的固定数据
    @PostMapping("/findHistoryForPersonage")
    @ApiOperation("个人中心课程历史记录")
    public CommonResult<List<HistoryVo>> findHistoryForPersonage(@RequestBody HistoryAcceptVo historyAcceptVo,HttpSession httpSession) {
//        C端用户登录的id，用于查询课程目录
        historyAcceptVo.setUserId(1L);
        List<HistoryVo> lists = courseFrontService.findHistoryForPersonage(historyAcceptVo);
        return CommonResult.success(lists);
    }

}
